package com.wedo.mall.activity.register;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.e.library.activity.EActivity;
import com.e.library.widget.ELabelValueView;
import com.wedo.mall.R;

import java.io.File;
import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;
import me.iwf.photopicker.PhotoPicker;

/**
 * Created by lxy on 2017/6/15.
 */

public class SellerInfoActivity extends EActivity {

    private static final int REQ_CATEGORY = 100;
    @BindView(R.id.iv_licence) ImageView iv_licence;
    @BindView(R.id.tv_licence) TextView tv_licence;

    @BindView(R.id.lvv_category) ELabelValueView lvv_category;

    @Override
    protected int layout() {
        return R.layout.activity_seller_info;
    }

    @Override
    protected void onActivityCreated(Bundle state) {

    }

    @OnClick(R.id.lvv_category)
    protected void onCategoryClick(){
        toActivityForResult(SellerCategoryActivity.class,REQ_CATEGORY);
    }

    @OnClick(R.id.ll_licence)
    protected void onLicenceClick(){
        PhotoPicker.builder()
                .setPhotoCount(1)
                .setShowCamera(true)
                .setShowGif(false)
                .setPreviewEnabled(true)
                .start(this, PhotoPicker.REQUEST_CODE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode !=RESULT_OK || data == null) return;

        switch (requestCode){
            case PhotoPicker.REQUEST_CODE:
                tv_licence.setVisibility(View.GONE);
                ArrayList<String> photos = data.getStringArrayListExtra(PhotoPicker.KEY_SELECTED_PHOTOS);
                Glide.with(this).fromFile().load(new File(photos.get(0))).into(iv_licence);
                break;
            case REQ_CATEGORY:
                String category = data.getStringExtra("category");
                lvv_category.setValueText(category);
                break;
        }
    }
}
